package org.study.dynamic.ds.starter;

import com.baomidou.dynamic.datasource.DynamicRoutingDataSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import javax.sql.DataSource;
import java.util.Map;

/**
 * 作用描述
 *
 * @author doveylovey
 * @version v1.0.0
 * @email 1135782208@qq.com
 * @date 2023年06月08日
 */
@Component
public class MyCommandLineRunner implements CommandLineRunner {
    @Autowired
    private DynamicRoutingDataSource dataSource;

    @Override
    public void run(String... args) throws Exception {
        Map<String, DataSource> dataSourceMap = dataSource.getDataSources();
        dataSourceMap.forEach((dsName, dataSource) ->
                System.out.println("当前数据源名称：" + dsName + "，数据源信息：" + dataSource)
        );
    }
}
